#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:6031)
#include<stdio.h>
#include<stdlib.h>

void CountSort(int* a, int n)
{
	int max = a[0], min = a[0];
	for (int i = 0; i < n - 1; i++)
	{
		if (a[i + 1] > max)
		{
			max = a[i + 1];
		}
		if (a[i + 1] < min)
		{
			min = a[i + 1];
		}
	}
	int* count = (int*)calloc((max-min+1),sizeof(int));
	if (count == NULL)
	{
		perror("calloc fail");
		return;
	}
	for (int i = 0; i < n; i++)
	{
		count[a[i]-min]++;
	}
	int i = 0;
	for (int j = 0; j < max-min+1; j++)
	{
		if (count[j] != 0)
		{
			while (count[j]--)
			{
				a[i] = j+min;
				i++;
			}
		}
	}
}
int main()
{
	int a[] = { 2,5,3,0,2,3,0,3 };
	int n = sizeof(a) / sizeof(int);
	CountSort(a, n);
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}